<template>
  <div class="info-key-space-root info-root">
    <div class="info-title">
      缓存命中率
    </div>
    <div class="info-content msg-info-content keyspace-content">
      <div class="keyspace-left">
        <div>命中成功：<el-tag type="info">{{ redisInfo.keyspace_hits }}</el-tag>
        </div>
        <div>命中失败：<el-tag type="info">{{ redisInfo.keyspace_misses }}</el-tag>
        </div>
        <div>命中总数：<el-tag type="info">{{ redisInfo.keyspace_all }}</el-tag>
        </div>
      </div>
      <div class="keyspace-right">
        {{ redisInfo.keyspace_rate }}%
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";

const redisInfo = ref({
  keyspace_hits: 0,
  keyspace_misses: 0,
  keyspace_all: 0,
  keyspace_rate: 0
})

const initMap = (info: any) => {
  redisInfo.value.keyspace_hits = Number(info.keyspace_hits);
  redisInfo.value.keyspace_misses = Number(info.keyspace_misses);
  redisInfo.value.keyspace_all = redisInfo.value.keyspace_hits + redisInfo.value.keyspace_misses;
  redisInfo.value.keyspace_rate = Number(Number(redisInfo.value.keyspace_hits / redisInfo.value.keyspace_all * 100).toFixed(0));
}

defineExpose({
  initMap
})
</script>

<style scoped lang="scss">
.info-key-space-root {
  @include box(100%, 100%);
  color: var(--el-text-color-regular);

  .info-title {
    @include themeColor(#AE564C, #aa4d45)
  }

  .keyspace-content {
    @include flex(row);

    .keyspace-left {
      @include box(45%, 100%);
      @include flex(column, space-around, flex-start);
      @include font(12px, 500);
      box-sizing: border-box;
    }

    .keyspace-right {
      @include box(55%, 100%);
      @include flex(row, center, center);
      @include font(90px, 700);
      @include themeColor(#AE564C, #aa4d45);
      box-sizing: border-box;
      text-shadow: 2px 2px 5px rgba(0, 0, 0, .4);

      [class="dark"] & {
        text-shadow: 2px 2px 5px rgba(188, 102, 102, 0.6);
      }
    }
  }
}
</style>